package com.cskaoyan.javase.recursion._2testdept;

/**
 * @description: 测试递归的深度/玩具
 * @author: wuguidong@cskaoyan.onaliyun.com
 **/

public class Demo {
    public static void main(String[] args) {
        sum(0);
    }

    public static int sum(int a) {
        //int b = 1000;
        try { //try代码块中写可能会出现异常的正常的代码逻辑
            return a + sum(a - 1);
        } catch (StackOverflowError error) {
            //catch代码块是当try当中产生了异常，并且刚好被捕获时会执行
            System.out.println("sum方法" + a + "层");
        }
        return 0;
    }
}
